﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：数据字典明细管理
 */

var refreshGird;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                top.selectedDataItemRow = null;
                var parentId = $('#gridtable').jfGridValue('id') || '0';
                learun.layerForm({
                    id: 'form',
                    title: '添加记录',
                    url: config.webportal_server + 'pages/salary/stand/subsidy/form.html?access_token=' + config.getToken().access_token,
                    width: 500,
                    height: 370,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGird);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                top.selectedDataItemRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑记录',
                        url: config.webportal_server + 'pages/salary/stand/subsidy/form.html?access_token=' + config.getToken().access_token,
                        width: 500,
                        height: 370,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGird);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('该动作执行后此项将彻底被删除，是否确认删除该项?', function (res) {
                        if (res) {
                            learun.deleteForm(config.base_server() + 'gzstandsubsidys/' + keyValue + '?access_token=' + config.getToken().access_token, {keyValue: keyValue}, function () {
                                refreshGird();
                            });
                        }
                    });
                }
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'gzstandsubsidys/list?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '工资待遇', name: 'levels', width: 200, align: 'left'},
                    {label: '实际职务', name: 'job', width: 200, align: 'left'},
                    {
                        label: '通讯费', name: 'value', width: 150, align: 'right',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2);
                        },
                    },
                    {label: '排序', name: 'sort', width: 80, align: 'center'},
                    {label: "备注", name: "description", width: 200, align: "left"}
                ],
                dblclick: function (row) {
                    var keyValue = row;
                    top.selectedDataItemRow = $('#gridtable').jfGridGet('rowdata');
                    if (learun.checkrow(keyValue)) {
                        learun.layerForm({
                            id: 'form',
                            title: '编辑记录',
                            url: config.webportal_server + 'pages/salary/stand/subsidy/form.html?access_token=' + config.getToken().access_token,
                            width: 500,
                            height: 370,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshGird);
                            }
                        });
                    }
                },
                isTree: true,
                mainId: 'id',
                parentId: 'parentId',
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGird = function () {
        page.search();
    };

    page.init();
}


